﻿/*
=======================================================
    WarehousePosition【仓库库位】
=======================================================
*/

namespace Services
{
    public interface IWarehousePositionLogic : ILogic<WarehousePositionModel, WarehousePositionFilterModel>
    {
        int UpdateIsDelete(bool flag, params int[] ids);
    }


    public class WarehousePositionLogic : BaseLogic<WarehousePositionModel, WarehousePositionFilterModel, WarehousePosition, IWarehousePositionRepository, IWarehousePositionMapping, IWarehousePositionService>, IWarehousePositionLogic
    {
        private readonly ICreateCode _ICreateCode;

        public WarehousePositionLogic(ICurrentUser currentUser, IWarehousePositionRepository repository, IWarehousePositionMapping mapping, IWarehousePositionService service, ICreateCode iCreateCode)
            : base(currentUser, repository, mapping, service)
        {
            _ICreateCode = iCreateCode;
        }

        #region 启用/禁用  UpdateIsDelete
        public int UpdateIsDelete(bool flag, params int[] ids)
        {
            return _repository.UpdateIsDelete(flag, ids);
        }
        #endregion

        public override WarehousePositionModel Insert(WarehousePositionModel model)
        {
            if (model.Code.IsEmpty())
            {
                model.Code = _ICreateCode.GetWarehousePositionCode();
            }

            if (_ICreateCode.WarehousePositionCodeExists(model.Code))
            {
                throw new CustomException("编码重复！");
            }

            return base.Insert(model);
        }
    }
}
